/*
 * @Author: Wangjun
 * @Date: 2023-09-13 09:44:12
 * @LastEditTime: 2023-09-22 15:34:20
 * @LastEditors: Wangjun
 * @Description:算子模块
 * @FilePath: \nodex\nodetime\clock.go
 * hnxr
 */
package nodetime

import (
	"time"

	"gitee.com/hnxr_1/nodex"
)

var gTZ = int64(0) //时区

func init() {
	_, t := time.Now().Zone()
	gTZ = int64(t)
	nodex.Reister(new(Clock))
}

// Clock 延时接通
type Clock struct {
	nodex.Node
	Y nodex.Double `remark:"输出Y,,out"`
}

func (m *Clock) GetModelID() int {
	return nodex.ModTimer
}

/**
 * @description:
 * @return {*}
 */
func (m *Clock) GetName() string {
	return "CLOCK"
}

/**
 * @description: 注册数据
 * @return {*}
 */
func (m *Clock) RegData() []byte {
	return nodex.MakeRegData(m, "时分秒", m.GetName(), "")
}

func (m *Clock) Calc() (err error) {
	now := Now() + gTZ
	now = now % 86400
	hh := now / 3600
	mm := (now % 3600) / 60
	ss := now % 60
	m.Y.Value = float64(hh*10000 + mm*100 + ss)
	return
}
